/**
 * 
 */
package uk.co.altv.simpledb.operation;

import uk.co.altv.simpledb.Connection;

/**
 * @author niki
 *
 */
public abstract class Operation implements IOperation {

	protected static final class Key {
		public static final String AWS_ACCESS_KEY_ID = "AWSAccessKeyId";
		public static final String ACTION = "Action";
		public static final String VERSION = "Version";
		public static final String ITEM_NAME = "ItemName";
		public static final String TIMESTAMP = "Timestamp";
		public static final String SIGNATURE = "Signature";
		public static final String NEXT_TOKEN = "NextToken";
		public static final String DOMAIN_NAME = "DomainName";
		public static final String SIGNATURE_METHOD = "SignatureMethod";
		public static final String SIGNATURE_VERSION = "SignatureVersion";
		public static final String SELECT_EXPRESSION = "SelectExpression";
		public static final String MAX_NUMBER_OF_DOMAINS = "MaxNumberOfDomains";
		public static final String CONSISTENT_READ = "ConsistentRead";
	}
	protected String action = "";
	protected boolean hasMoreItems = false;
	
	protected String getIdAndAction(Connection endpoint) {
		return Key.AWS_ACCESS_KEY_ID + "=" + endpoint.getAccessKey() + appendData(Key.ACTION, this.action, endpoint);
	}
	protected String doTail(Connection endpoint) {
		return appendData(Key.SIGNATURE_METHOD, endpoint.getSignatureMethod(), endpoint)
			+ appendData(Key.SIGNATURE_VERSION, endpoint.getSignatureVersion(), endpoint)
			+ appendData(Key.TIMESTAMP, endpoint.getTimestamp(), endpoint)
			+ appendData(Key.VERSION, endpoint.getVersion(), endpoint);
	}
	/**
	 * @param key
	 * @param value
	 * @return
	 */
	protected String appendData(String key, String value, Connection endpoint) {
		return "&" + endpoint.encode(key) + "=" + ((value == null) ? "" : endpoint.encode(value));
	}

	public boolean hasMoreItems() {
		return hasMoreItems;
	}

}
